from pygame import *
from config_reader import *
from tool import *
from sys import exit
from os import startfile
from math import sin

class Face:
    def __init__(self):
        init()
        self.screen = display.set_mode((650,500))
        display.set_caption("默写器")
        self.screen.fill("lightskyblue")
        self.word = reader().word.get("face")
        print(self.word)
        self.button_font = font.SysFont("Microsoft YaHei",25,True,"black")
        self.time = 0


    def main(self):
        self.start = self.button_font.render(self.word.get("start"), False, "black", "pink")
        self.setting = self.button_font.render(self.word.get("setting"), False, "black", "pink")
        self.quit = self.button_font.render(self.word.get("quit"), False, "black", "pink")
        self.logo = image.load("./resources/image/logo.png").convert_alpha()
        self.title = image.load("./resources/image/title.png").convert_alpha()
        self.update = image.load("./resources/image/update.png").convert_alpha()
        self.update = transform.scale(self.update,(350,250))


        def pain():

            self.logo_rect = Tool().animation_sin(self.time,0.075, 15)
            self.logo_size = Tool().animation_sin(self.time, 0.125, 5)
            self.logo_c = transform.scale(self.logo, (70-self.logo_size, 70-self.logo_size))
            self.logo_c = transform.rotate(self.logo_c,self.logo_rect)

            self.screen.fill("lightskyblue")
            self.screen.blit(self.start,(30,165))
            self.screen.blit(self.title, (150, 10))
            self.screen.blit(self.logo_c, (20, 20))
            self.screen.blit(self.update, (210, 150))
            self.screen.blit(self.setting, (30 + self.start.get_width()/2 - self.setting.get_width()/2, 165 + self.start.get_height() + 5))
            self.screen.blit(self.quit,(30 + self.start.get_width() / 2 - self.quit.get_width() / 2, 165 + self.start.get_height() + 5 + self.setting.get_height() +5))


        pain()
        while True:
            self.time = time.get_ticks() / 50
            self.fps = 1000 / 50
            for eve in event.get():
                if(eve.type == MOUSEBUTTONDOWN):
                    print(eve.pos)
                    print(self.start.get_rect().bottomleft)

                    if(Tool().button(self.start,(30,165),eve.pos)):
                        return "start"
                    if(Tool().button(self.update,(210, 150),eve.pos)):
                        startfile("update.html")
                    if(Tool().button(self.setting,(30 + self.start.get_width()/2 - self.setting.get_width()/2, 165 + self.start.get_height() + 5),eve.pos)):
                        return "setting"
                    if(Tool().button(self.quit,(30 + self.start.get_width() / 2 - self.quit.get_width() / 2, 165 + self.start.get_height() + 5 + self.setting.get_height() +5),eve.pos)):
                        print("[system]:writer over")
                        exit()

            pain()
            display.update()
